namespace Excavator.Tools
{
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using UnityEngine;
    public static class MeshFilterUtil
    {
        /// <summary>
        /// 获取meshFilter最前方的点 - todo 后续需要添加上物体的旋转信息
        /// </summary>
        /// <param name="meshFilter"></param>
        /// <returns></returns>
        public static Vector3 GetForeFrontVertice(this MeshFilter meshFilter)
        {
            Vector3[] vertices = meshFilter.GetAllVertices();
            Vector3 highestVerrtice = Vector3.zero;
            for (int i = 0; i < vertices.Length; i++)
            {
                if (highestVerrtice.z < vertices[i].z)
                {
                    highestVerrtice = vertices[i];
                }
            }
            return highestVerrtice;
        }

        /// <summary>
        /// 获取meshFilter最高的点 - todo 后续需要添加上物体的旋转信息
        /// </summary>
        /// <param name="meshFilter"></param>
        /// <returns></returns>
        public static Vector3 GetHighestVertice(this MeshFilter meshFilter)
        {
            Vector3[] vertices = meshFilter.GetAllVertices();
            Vector3 highestVerrtice = Vector3.zero;
            for (int i = 0; i < vertices.Length; i++)
            {
                if (highestVerrtice.y < vertices[i].y)
                {
                    highestVerrtice = vertices[i];
                }
            }
            return highestVerrtice;
        }

        /// <summary>
        /// 获取MeshFilter的所有顶点
        /// </summary>
        /// <param name="meshFilter"></param>
        /// <returns></returns>
        public static Vector3[] GetAllVertices(this MeshFilter meshFilter)
        {
            Mesh mesh = meshFilter.sharedMesh;
            return mesh.vertices;
        }
    }
}